package com.menu.web.controller.img;

import com.menu.common.annotation.Log;
import com.menu.common.core.controller.BaseController;
import com.menu.common.core.domain.AjaxResult;
import com.menu.common.core.page.TableDataInfo;
import com.menu.common.enums.BusinessType;
import com.menu.common.utils.poi.ExcelUtil;
import com.menu.system.domain.MenuImages;
import com.menu.system.service.IMenuImagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * imgController
 *
 * @author ruoyi
 * @date 2024-09-22
 */
@RestController
@RequestMapping("/system/images")
public class MenuImagesController extends BaseController {
    @Autowired
    private IMenuImagesService menuImagesService;

    /**
     * 查询img列表
     */
    @PreAuthorize("@ss.hasPermi('system:images:list')")
    @GetMapping("/list")
    public TableDataInfo list(MenuImages menuImages) {
        startPage();
        List<MenuImages> list = menuImagesService.selectMenuImagesList(menuImages);
        return getDataTable(list);
    }

    /**
     * 导出img列表
     */
    @PreAuthorize("@ss.hasPermi('system:images:export')")
    @Log(title = "img", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MenuImages menuImages) {
        List<MenuImages> list = menuImagesService.selectMenuImagesList(menuImages);
        ExcelUtil<MenuImages> util = new ExcelUtil<MenuImages>(MenuImages.class);
        util.exportExcel(response, list, "img数据");
    }

    /**
     * 获取img详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:images:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(menuImagesService.selectMenuImagesById(id));
    }

    /**
     * 新增img
     */
    @PreAuthorize("@ss.hasPermi('system:images:add')")
    @Log(title = "img", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MenuImages menuImages) {
        return toAjax(menuImagesService.insertMenuImages(menuImages));
    }

    /**
     * 修改img
     */
    @PreAuthorize("@ss.hasPermi('system:images:edit')")
    @Log(title = "img", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MenuImages menuImages) {
        return toAjax(menuImagesService.updateMenuImages(menuImages));
    }

    /**
     * 删除img
     */
    @PreAuthorize("@ss.hasPermi('system:images:remove')")
    @Log(title = "img", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(menuImagesService.deleteMenuImagesByIds(ids));
    }
}
